package scalaSci.math.plot.plots;

import java.awt.*;

import javax.swing.*;

import scalaSci.math.plot.*;
import scalaSci.math.plot.render.*;

public class LineMarksPlot extends ScatterPlot {
        public Font defaultFont = new Font("Arial", Font.BOLD, 12);
	public boolean draw_dot = false;
        public String defaultMark ="X";
        public boolean connectLines = true;
        public int skipPoints = 5;
        public Color markDefaultColor = Color.BLUE;
        public Color lineDefaultColor = Color.RED;


	public LineMarksPlot(String n, Color c, Font f, char mark, double[][] _XY) {
		super(n, c, _XY);
                defaultFont = f;
                defaultMark = String.valueOf(mark);
	}
        
        public LineMarksPlot(String n, Color c, boolean[][] _pattern, double[][] _XY) {
		super(n, c, _pattern, _XY);
	}

        public LineMarksPlot( String n,  Color c,  boolean[][] _pattern,  double[]  _X,   double [] _Y)  {
              super(n, c, _pattern, _X, _Y);
	}

	public LineMarksPlot(String n, Color c, int _type, int _radius, double[][] _XY) {
		super(n, c, _type, _radius, _XY);
	}

	public LineMarksPlot(String n, Color c, double[][] _XY) {
		super(n, c, _XY);
	}

	public void plot(AbstractDrawer draw, Color c) {
		if (!visible)
			return;

		if (draw_dot)
			super.plot(draw, c);
                draw.setFont(defaultFont);
                draw.setColor(markDefaultColor);
		draw.setLineType(AbstractDrawer.CONTINOUS_LINE);
		for (int i = 0; i < XY.length - 1-skipPoints;  i+=skipPoints)
			draw.drawText(defaultMark, XY[i][0], XY[i][1]);
                draw.setColor(lineDefaultColor);
                for (int i=0; i < XY.length - 1; i++)
                    draw.drawLine(XY[i], XY[i+1]);
	}

           /*
           b     blue          .     point              -     solid
           g     green         o     circle             :     dotted
           r     red           x     x-mark             -.    dashdot 
           c     cyan          +     plus               --    dashed   
           m     magenta       *     star             (none)  no line
           y     yellow        s     square
           k     black         d     diamond
                               v     triangle (down)
                               ^     triangle (up)
                               <     triangle (left)
                               >     triangle (right)
                               p     pentagram
                               h     hexagram
           */        
        
        // Matlab-like patterns
public void plot(AbstractDrawer draw, Color c,  String  lineType) {
		if (!visible)
			return;

		if (draw_dot)
			super.plot(draw, c);

		draw.setColor(c);
                draw.drawText("sterg", XY[0][10], XY[1][11]);
                
                 if  (lineType.equals(":"))
                    draw.setLineType(AbstractDrawer.DOTTED_LINE);
                else if  (lineType.equals("-."))
                    draw.setLineType(AbstractDrawer.CROSS_DOT);
                else if (lineType.equals("."))
                    draw.setLineType(AbstractDrawer.DOTTED_LINE);
                else if (lineType.equals("s")) {
                    draw.setDotPattern(AbstractDrawer.DOT_SQUARE_PATTERN);
                    draw.setLineType(AbstractDrawer.PATTERN_DOT);
                }
                else if (lineType.equals("v")) {
                    draw.setDotPattern(AbstractDrawer.DOT_TRIANGLE_PATTERN);   
                    draw.setLineType(AbstractDrawer.PATTERN_DOT);
                }
                else
		    draw.setLineType(AbstractDrawer.CONTINOUS_LINE);
		
                for (int i = 0; i < XY.length - 1; i++)
			draw.drawLine(XY[i], XY[i + 1]);
	}

public static void main(String[] args) {
		Plot2DPanel p2 = new Plot2DPanel();
                

			double[][] XYZ = new double[100][2];
			for (int j = 0; j < XYZ.length; j++) {
				XYZ[j][0] = 2*Math.PI*(double)j/XYZ.length;
				XYZ[j][1] = Math.sin(XYZ[j][0]);
			}
                        double[][] XYZ2 = new double[100][2];
			for (int j = 0; j < XYZ2.length; j++) {
				XYZ2[j][0] = 2*Math.PI*(double)j/XYZ.length;
				XYZ2[j][1] = Math.sin(2*XYZ2[j][0]);
			}
	
			p2.addLinePlot("sin" , Color.RED, AbstractDrawer.DOTTED_LINE, XYZ);
                        p2.setBackground(new Color(200,0,0));
                        p2.addLinePlot("sin2", XYZ2);
		

		p2.setLegendOrientation(PlotPanel.SOUTH);
		new FrameView(p2).setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

		Plot3DPanel p = new Plot3DPanel();

			XYZ = new double[100][3];
			for (int j = 0; j < XYZ.length; j++) {
				XYZ[j][0] = 2*Math.PI*(double)j/XYZ.length;
				XYZ[j][1] = Math.sin(XYZ[j][0]);
				XYZ[j][2] = Math.sin(XYZ[j][0])*Math.cos(XYZ[j][1]);
			}
			p.addLinePlot("toto" , XYZ);
                        
		
		p.setLegendOrientation(PlotPanel.SOUTH);
		new FrameView(p).setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
}